<template>
   <a-layout-content style="margin: 0 16px">
    <a-button type="primary" @click="goback" style="margin-bottom: 20px"
      >返回</a-button
    >
      <div :style="{ padding: '24px', background: '#fff', minHeight: '30px' }">
        <p class="titleMess">基础信息</p>
        <a-divider />
          <a-form
          ref="formRef"
          :model="addTaskForm"
        >
          <a-form-item ref="taskSceneId" label="业务场景" name="taskSceneId" :required="true">
            <a-select
              v-model:value="addTaskForm.taskSceneId"
              placeholder="请选择任务场景"
              @change="selectScene"
              :options="sceneOptions"
            />
            </a-select>
          </a-form-item>
         <a-form-item ref="taskObject" label="任务级别" name="taskObject"  :required="true">
            <span>{{taskObject}}</span>
          </a-form-item>
          <a-form-item ref="taskTitle" label="任务名称" name="taskTitle" :required="true">
            <a-input
              placeholder="填写名称，最多40字"
              v-model:value="addTaskForm.taskTitle"
              autoComplete="off"
              :maxLength="40"
            />
          </a-form-item>
          <a-form-item
            ref="taskDescription"
            label="任务说明"
            name="taskDescription"
            :required="true"
          >
            <a-textarea
              v-model:value="addTaskForm.taskDescription"
              placeholder="填写说明，最多400字"
              style="min-height: 180px"
              auto-size
              :maxLength="400"
            />
          </a-form-item>
           <a-form-item ref="execType" label="执行时效" name="execType" :required="true">
          <span>实时触发</span>
          </a-form-item>
           <a-form-item ref="expireTime" label="有效期" name="expireTime" :required="true">
              <a-input-number
                style="width: 80px"
                id="inputNumber"
                v-model:value="addTaskForm.expireTime"
                :min="1"
                :max="10000"
                :controls="false"
                @change="changeNumber"
              />
              <span style="margin-left:10px">小时</span>
              </a-select>
            </a-form-item>
               <a-form-item ref="endProcess" label="到期是否执行" name="endProcess" :required="true">
            <a-radio-group
              v-model:value="addTaskForm.endProcess"
              :options="endProcessDate"
              :disabled="noCarry"
            />
          </a-form-item>
           <a-form-item
            label="执行导购"
            name="guideType"
            v-if="addTaskForm.taskObject === 2 "
             :required="true"
          >
           <span v-if="addTaskForm.taskType===13">由业务系统传参——内淘单所属门店对应的所有导购</span>
          </a-form-item>
            <a-form-item
            label="执行导购"
            name="guideType"
           v-if="addTaskForm.taskObject===1"
             :required="true"
          >
          <span v-if="addTaskForm.taskType===10">由业务系统传参——box自主要盒工单会员对应的专属导购</span>
           <span v-if="addTaskForm.taskType===11||addTaskForm.taskType===12">由业务系统传参——box服务单会员对应的专属导购</span>
            </a-form-item>
          </a-form>
              <!-- <UplpadEnclosure  @chooseData="getUploadData" :mediaDetail="mediaDetail" ref="uploadEnclosure"/> -->
        </a-form>
        <div>
          <a-button class="addBtn" @click="addBtn(0)" type="primary" v-if="!this.$route.query.publishStatus"
            >保存</a-button
          >
          <a-button
            class="addBtn"
            style="margin-left: 20px"
            @click="addBtn(1)"
            type="primary"
            v-if="!this.$route.query.publishStatus"
            >发布</a-button
          >
        </div>
      </div>
       
   </a-layout-content>
</template>

<script>
import {getRealTaskInfo,updateRealTask} from "@/api/task/taskrelese"
import { getOpenScene } from "@/api/task/taskscene";
import UplpadEnclosure from "@/components/task/uploadEnclosure/index.vue"; //上传材料
export default {
    components:{UplpadEnclosure},
  data () {
    return {
       
        enclosure:'',
        noCarry:true,
        taskObject:'',
        addTaskForm:{},
         sceneOptions:[],
          endProcessDate: [
        { label: "是", value: 1 },
        { label: "否", value: 2 },
      ],
    }
  },

  created () {
    this.getScene()
    this.getDatas()
  
    console.log(this.$route.query.publishStatus);
  },

  methods: {
    // // 传递材料信息
    // getUploadData(value){
    //   this.enclosure=value
    //   console.log("uploadDatas after   ",value);
    // },
    addBtn(val){
        let id=this.$route.query.id
        let data={
            publishStatus:val,
            id:id,
             taskSceneId: this.addTaskForm.taskSceneId, //场景id
              taskTitle: this.addTaskForm.taskTitle, //任务名称
               taskDescription: this.addTaskForm.taskDescription, //任务说明
               expireTime:Number(this.addTaskForm.expireTime), //有效期
                taskType: Number(this.addTaskForm.taskType), //任务类型
        }
        updateRealTask(data,res=>{
            console.log("updateRealTask  ",res);
            if(res.code==200){
                this.$message.success("编辑成功！");
                this.$router.push("/task/release")
            }else{
                this.$message.error("编辑失败！");
            }
        })
         
    },
      changeNumber(val){
      console.log(val);
       this.addTaskForm.expireTime=Number(val)
    },
      goback() {
      this.$router.back();
    },
    getDatas(){
        let id=this.$route.query.id
        console.log(id);
        getRealTaskInfo({id},res=>{
            console.log(res);
          
            this.addTaskForm=res.data
            this.addTaskForm.taskSceneId=res.data.taskSceneId+'';
            let taskObject=res.data.taskObject
            if(taskObject===1){
                this.taskObject="导购任务"
            }else if(taskObject===2){
                this.taskObject='门店任务'
            }
        })
    },
 // 获取场景
    getScene() {
      let data = {};
    
      getOpenScene(data, (res) => {
        console.log(res);
        this.sceneOptions = res.data;
      });
    },
     selectScene(val, opt) {
  
      console.log(val,opt);
      this.addTaskForm.taskSceneId = val;
      this.addTaskForm.taskGroupId = opt.taskGroupId;
    },

  }
}
</script>

<style scoped lang='less'>
.titleMess {
  font-size: 18px;
}
.ant-divider {
  margin: 15px 0;
}
.ant-form {
  .ant-select {
    width: 170px;
    margin-right: 10px;
  }
  .ant-input {
    width: 200px;
  }
  .ant-upload-list {
    width: 200px;
  }
}
.addBtn {
  margin-top: 20px;
}
.tishi {
  margin-left: 5px;
  font-size: 12px;
  color: #7f7f7f;
}
.add_btn,
.del_btn {
  padding: 0 10px;
  cursor: pointer;
  margin-left: 10px;
}
.getId {
  font-size: 12px;
  margin-left: 10px;
}
.ant-form-item{
  display: flex;
}
.ml{
  margin-left:15px;
}
</style>
